package com.maven.booksystem.config;


import com.maven.booksystem.interceptor.LoginInterceptor;
import org.apache.tomcat.util.buf.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.Arrays;
import java.util.List;


@Configuration
// 这里 就是 注册 拦截器 ： 就相当于 确定作用范围
public class WebConfig implements WebMvcConfigurer {
    @Autowired
    private LoginInterceptor loginInterceptor;

    List<String> list = Arrays.asList("/user/login",
            "/css/**",
            "/js/**",
            "/pic/**",
            "/**/login.html");


    public void addInterceptors(InterceptorRegistry registry) {
//        //  这里 addPathPatterns 添加 拦截器  之后， 利用  excludePathPatterns 来 配置 作用范围
//        registry.addInterceptor(loginInterceptor).addPathPatterns("/**").
//                excludePathPatterns("/user/login").
//                excludePathPatterns("/css/**").
//                excludePathPatterns("/js/**").
//                excludePathPatterns("/pic/**").
//                excludePathPatterns("/**/*.html");

        //当然，  excludePathPatterns 还可以进行传递 List 数组
        registry.addInterceptor(loginInterceptor).addPathPatterns("/**").
                excludePathPatterns(list);
    }
}
